﻿using System;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectActualResourceHandler
{
    public class AddNewActualResourceUsage
    {
        private readonly ProjectActualResourceUsageRepository _projectActualResourceUsageRepository;
        private readonly ProjectTaskRepository _projectTaskRepository;

        public AddNewActualResourceUsage(ProjectActualResourceUsageRepository projectActualResourceUsageRepository)
        {
            _projectActualResourceUsageRepository = projectActualResourceUsageRepository;
        }

        public AddNewActualResourceUsage()
        {
            _projectActualResourceUsageRepository = new ProjectActualResourceUsageRepository();
            _projectTaskRepository = new ProjectTaskRepository();
        }

        public virtual void Execute(string projectId, string taskId, string userName, string userId)
        {
            try
            {
                // convert
                short cPrjId = short.Parse(projectId);
                short cTaskId = short.Parse(taskId);

                TASK projectTasksData = _projectTaskRepository.GetTaskByGenTaskId(cTaskId);
                short cGenTaskId = (short)projectTasksData.GEN_TASK_ID;

                // set latest from DB  DateTime dt, float hours
                _projectActualResourceUsageRepository.AddNewActualResourceUsage(cPrjId, cGenTaskId, userName, userId);
                
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
            }
        }

    }
}
